<template>
  <el-dialog
    title="客户注销"
    :visible.sync="dialogVisible"
    width="30%"
    :before-close="handleClose"
  >

    <lb-table
      ref="a"
      v-loading="$loadingPlugin.fetchData"
      :data="tableData.data"
      :column="tableData.column"
      @selection-change="handleSelectionChange"
    />
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="success">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { customerInfo } from '@/api'
  export default {
    name: 'huiFu',
    props: {
      huiFuFn: {
        type: Function
      }
    },
    data() {
      return {
        csmInfo: {},
        dialogVisible: false,
        phones: null,
        tableData: {
          column: [

            {
              prop: 'csmPhone',
              label: '电话'
              // render: (h, { row }) => <span>{ row.time && parseTime(row.time, '{y}-{m}-{d} {h}:{i}:{s}') }</span>
            },
            {
              type: 'selection'
            }

          ],
          data: []
        }
      }
    },
    methods: {
      async open(temp, code) {
        this.query = { ...temp }
        this.dialogVisible = true
        await this.searchCsmInfo(code)
      },
      async searchCsmInfo(code) {
        const params = {
          csmCode: code
        }
        const res = await customerInfo(params)
        if (res.success && res.data) {
          this.tableData.data = res.data.phoneItems
        }
      },
      success() {
        // invalidStr
        const params = { ...this.query, phones: this.phones }
        // console.log(this.$parents)
        // console.log(this.huiFuFn)
        console.log(params)
        if (!this.phones) {
          this.$message.warning('请选择要恢复的电话')
          return
        }
        this.huiFuFn(params)
        this.dialogVisible = false
      },
      handleSelectionChange(val) {
        console.log(val)
        var list = val.map(l => l.csmPhone)
        if (val) {
          this.phones = list.join(',')
        } else {
          this.phones = ''
        }
        // console.log(this.phones)
      },
      handleClose(done) {
        // this.$confirm('确认关闭？')
        //   .then(_ => {
        //     done()
        //   })
        //   .catch(_ => {})
      }
    }
  }

</script>

<style scope lang="scss">

</style>
